//
//  SDLeftTableViewController.m
//  WZSOA
//
//  Created by xsd on 16/6/14.
//  Copyright © 2016年 刘沿. All rights reserved.
//

#import "SDLeftTableViewController.h"
#import "FSCSCell.h"

@interface SDLeftTableViewController ()
@property (nonatomic,strong) NSMutableArray *contentArray;

@end

@implementation SDLeftTableViewController

static NSString * const reuseIdentifier = @"reuseIdentifier";

- (NSMutableArray *)contentArray{

    if (_contentArray == nil) {
        
        _contentArray = [NSMutableArray array];
    }

    return _contentArray;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    //默认选中第一行
    [self.tableView  selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:UITableViewScrollPositionNone];
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.navigationBar.translucent = NO;

    NSString *path = [[NSBundle mainBundle] pathForResource:@"mainPlist" ofType:@"plist"];
    
    NSMutableArray *array = [NSMutableArray arrayWithContentsOfFile:path];
    self.contentArray = array;

    [self.tableView registerNib:[UINib nibWithNibName:@"FSCSCell" bundle:nil] forCellReuseIdentifier:reuseIdentifier];

}


#pragma mark - Table view data source
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.contentArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    FSCSCell* cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifier];

    if (cell == nil) {
        
        cell = [FSCSCell CSCell];
    }
    
    NSDictionary *dict = self.contentArray[indexPath.row];

    cell.dict = dict;
    
    cell.backgroundColor = [UIColor colorWithRed:0/255.0 green:94/255.0 blue:219 /255.0 alpha:1];
    
//取消分割线
//    [tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
   
    return cell;
    
}
- (void)didChange:(NSNotification *)noti{
    
    NSIndexPath *index = noti.userInfo[@"index"];
    
    UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:index];
    
    cell.backgroundColor = [UIColor colorWithRed:0/255.0 green:94/255.0 blue:219 /255.0 alpha:1];
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{


    return 100;

}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor colorWithRed:0/255.0 green:70/255.0 blue:163 /255.0 alpha:1];

    if (self.myBlock) {
        self.myBlock(indexPath.row);
    }
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didChange:) name:UIDeviceOrientationDidChangeNotification object:@{@"index":indexPath}];
    

}

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath{

    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    
    cell.backgroundColor = [UIColor colorWithRed:0/255.0 green:94/255.0 blue:219 /255.0 alpha:1];
   [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didChange:) name:UIDeviceOrientationDidChangeNotification object:@{@"index":indexPath}];
    
}




@end









